<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<?php
session_start();
if (empty($_SESSION["loginusername"])) {
                            Header("Location: firstphp.php");
                        }
if (!empty($_SESSION["userType"])) {
    $userType = $_SESSION["userType"];
}

?>
<html>
    <head>
        <title>Manage Password</title>
        <link rel="stylesheet" type="text/css" href="http://localhost/Eldercare/jquery/easyui.css">
        <link rel="stylesheet" type="text/css" href="http://localhost/Eldercare/jquery/icon.css">
        <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery-1.6.min.js"></script>
        <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery-1.4.4.min.js"></script>

        <script type="text/javascript" src="http://localhost/Eldercare/jquery/jquery.easyui.min.js"></script>
        <style type="text/css">
            #fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                color:#666;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:5px;
            }
            .fitem label{
                display:inline-block;
                width:80px;
            }
        </style>
        <link href="http://localhost/Eldercare/finalstyle.css" rel="stylesheet" type="text/css" media="all" />	
    </head>
    <style type="text/css">
        body {
            background: #FFFFFF url("images/bg.png") repeat;
            background-attachment:fixed;
        }
        .button 
        {
            background-color:beige;
            cursor:pointer; }

        .btn
        {
            background-color:#FFF5EE;
            cursor:pointer;
        }
        
    </style>
    <body>
        <div class="banner"></div>
        <div id="main">
            <div class="left-wrapper">
                <div class="logo">
                </div>
                <div class="menu-wrapper">
                    <div id='cssmenu' >     
                        <ul>


                         <?php
                                if ($userType == "Therapy Assistant") {
                                    //if TA
                                    echo "<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li class='last'><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			 </ul>
			  </li>
			  <li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
		 <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
   <li class='last'><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
     
			 ";
                                } else if ($userType == "Centre Manager") {
                                    echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                                } else {
                                    echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
         <li><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/Centres.php'><span>Centres</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Activities.php'><span>Manage Current Activities</span></a></li>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li><a href='http://localhost/Eldercare/Holidays.php'><span>Holiday</span></a></li>
<li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                                }
                                ?>


                    </div>
                    <div class="clear"></div></div></div>
            <div class="content">
                <div class="content2">
                    <b style="float:right; margin: 0px 0 0 0">  
                        <br>
                        <?php
//session_start();
                        if (!empty($_SESSION["centreName"])) {
                            $Username = $_SESSION["loginusername"];
                            $centreName = $_SESSION["centreName"];
                            echo "Welcome, " . $Username . " ! <br>" . $centreName . " Branch";
                        } else {
                            $Username = $_SESSION["loginusername"];
                            echo "Welcome, " . $Username;
                        }
                        ?>

                        <?php
                        
                        ?>
                        <?php
//session_start();
// set timeout period in seconds
                        $inactive = 7200;
// check to see if $_SESSION['timeout'] is set
                        if (isset($_SESSION["timeout"])) {
                            $session_life = time() - $_SESSION["timeout"];
                            if ($session_life > $inactive) {
                                session_destroy();
                                Header("Location: Timeout.php");
                            }
                        }
                        $_SESSION["timeout"] = time();
                        ?>

                        <input type="submit" class="button" value="Logout" onclick="parent.location = 'logout.php'"></b>
                    <div class="clear"></div>

                    <form method='post'>
                        <h3><b>Old password:</b></h3>
                        <input type="text" name="oldPassword" id="oldPassword" value="Please Enter.." onFocus="if (this.value == 'Please Enter..') {
                                    this.value = '';
                                    this.type = 'Password';
                                }" onBlur="if (this.value == '') {
                                    this.value = 'Please Enter..';
                                    this.type = 'text';
                                }">
                        <h3><b>New password:</b></h3>
                        <input type="text" name="newPassword" id="newPassword" value="Please Enter.." onFocus="if (this.value == 'Please Enter..') {
                                    this.value = '';
                                    this.type = 'Password';
                                }" onBlur="if (this.value == '') {
                                    this.value = 'Please Enter..';
                                    this.type = 'text';
                                }">
                        <h3><b>Confirm password:</b></h3>
                        <input type="text" name="cfmPassword" id="cfmPassword"  value="Please Enter.." onFocus="if (this.value == 'Please Enter..') {
                                    this.value = '';
                                    this.type = 'Password';
                                }" onBlur="if (this.value == '') {
                                    this.value = 'Please Enter..';
                                    this.type = 'text';
                                }">
                        <p><input type="submit" name="btnSubmit" value="Change Password" id="btnSubmit" onClick=""></p>
                    </form>
                    <?php
                    if (isset($_POST['btnSubmit'])) {
                        $empty = "Please Enter..";
                        if ((!empty($_POST['oldPassword']) && !empty($_POST['newPassword']) && !empty($_POST['cfmPassword']) ) && ( $_POST['oldPassword'] != $empty && $_POST['newPassword'] != $empty && $_POST['cfmPassword'] != $empty)) {
                            $oldPassword = $_POST['oldPassword'];
                            $newPassword = $_POST['newPassword'];
                            $cfmPassword = $_POST['cfmPassword'];
                            $username = $_SESSION['loginusername'];
                            $oldPasswordhashed = md5($oldPassword);
                            include 'conn.php';
                            $select = mysql_query("select * from user WHERE Password = '" . $oldPasswordhashed . "' and Username ='" . $username . "'");
                            if (mysql_num_rows($select) == 1) {
                                if ($newPassword == $cfmPassword) {
                                    if ($oldPassword != $newPassword) {
                                        $newHashedPassword = md5($newPassword);
                                        $insert = mysql_query("update user set Password='$newHashedPassword' where Username='$username'");
                                        $login = "<font color=red> Your password has changed successfully!</font>";
                                    } else {
                                        $login = "<font color=red>Old Password and New Password is the same!</font>";
                                    }
                                } else {
                                    $login = "<font color=red>Passwords do not match!</font>";
                                }
                            } else {
                                $login = "<font color=red>Old Password is incorrect! Please enter again!</font";
                            }
                        } else {
                            $login = "<font color=red> Please fill up all the information!</font>";
                        }
                        echo $login;
                    }
                    ?>

                    <?php
                    // include("conn.php");
                    // if(isset($_POST['btnSubmit']))
                    // {
                    // //$checkanswer = $_POST["Password"];
                    // //$retrieve = "Select * from user where Password = '$checkanswer'";
                    // //$sql = "Select * from user where Password= '$checkanswer'";
                    // //$username = mysql_query($retrieve);
                    // $oldPassword = $_POST['oldPassword'];
                    // $newPassword = $_POST['newPassword'];
                    // $username = $_SESSION['loginusername'];
                    // $confirmPassword = $_POST['confirmPassword']; 
                    // if(empty($oldPassword) || empty($newPassword)||empty($confirmPassword))
                    // {
                    // if($newPassword==$confirmPassword)
                    // {
                    // $select = mysql_query("select * from user WHERE Password = '$oldPassword' and Username ='$username'"); 
                    // if(mysql_num_rows($select)==1)
                    // {
                    // $newHashedPassword = md5($newPassword);
                    // $insert = mysql_query("update user set Password='$newHashedPassword' where Username='$username'");
                    // echo "<font color=red> Your password has changed successfully!</font>";
                    // } 
                    // }
                    // else
                    // {
                    // echo "<font color=red> The passwords do not match. Please try again!";
                    // }
                    // }
                    // else
                    // {
                    // echo "<font color=red> Please fill up all the information!";
                    // }
                    // }
// 
                    ?>

                </div><br><div class="clear"></div></div>
        </div>
    </body> 
</html>
